package RocketMQ.HelloWorld;

import com.alibaba.rocketmq.client.exception.MQClientException;
import com.alibaba.rocketmq.client.producer.DefaultMQProducer;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.common.message.Message;

/**
 * Created by brossdong on 2017/12/20.
 * 发送信息
 */
public class Provider {

    public static void main(String[] args) throws MQClientException, InterruptedException {

        //1.创建消费者
        DefaultMQProducer producer = new DefaultMQProducer("quickstart_producer");
        //2.连接nameserver服务
        producer.setNamesrvAddr("172.16.113.141:9876;172.16.113.142:9876");

        producer.start();

        for (int i = 0;i < 100;i++) {
            try {
                //第一参数是主题,
                Message msg = new Message("TopicQuickStart","TagA",("hello rocketmq" + i).getBytes());
                //发送信息
                SendResult sendResult = producer.send(msg);
                System.out.println(sendResult);
            }catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }


        //关闭
        producer.shutdown();

    }

}
